package com.itheima.dao;

import com.itheima.domain.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import javax.swing.*;
import java.util.List;

/**
 * 在mybatis中针对CRUDE一共有四个注解
 * @SSelect  @Insert  @Update #Delete
 */
public interface IUser {

    /**
     * 查询所有用户
     * @return
     */
    @Select(value = "select * from user" )
    List<User> findAll();

    /**
     * 保存用户
     * @param user
     */
    @Insert("insert into user(username,address,sex,birthday) values(#{username},#{address},#{sex},#{birthday}) ")
    void saveUser(User user);

    /**
     * 更新 用户
     * @param  user
     */
    @Update("update user set username =#{username},sex=#{sex},address=#{address},birthday=#{birthday} where id = #{id}")
    void updateUser(User  user);

    /**
     * 删除用户
     * @param id
     */
    @Delete("delete from user where id = #{id}")
    void deleteUser (Integer id);

    /**
     * 根据ID查询用户
     * @param id
     * @return
     */
    @Select("select * from user where id = #{id}")
    User findById(Integer id);

    /**
     * 根据名称查询用户
     * @param username
     * @return
     */
//    @Select("select * from user where username like #{username}")
    @Select("select * from user where username like '%${value}%' ")
    List<User> findUserByName(String username);

    /**
     * 查询总记录数
     * @return
     */
    @Select("select  count(*) from user")
    int findTotal();

}
